package com.central.wx.controller

import cn.binarywang.wx.miniapp.api.WxMaService
import com.central.wx.config.WxMaConfiguration
import com.central.wx.config.WxMaProperties
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController


/**
 * @author  fly
 * @date  2021/5/26 16:58
 * @version 1.0
 */
@Api(tags = ["wx相关api"])
@RestController
@RequestMapping("wx/user")
@EnableConfigurationProperties(WxMaProperties::class)
open class WxMaUserController(wxMaProperties: WxMaProperties) {


    private var wxMaService: WxMaService = WxMaConfiguration.getMaService(wxMaProperties.configs[0].appid)

    @GetMapping("/login/{code}")
    @ApiOperation("登录")
    fun login(@PathVariable code: String): String? = wxMaService.userService.getSessionInfo(code).openid


}